//***********************Bismillah-ir-Rahman-ir-Rahim******************************\
//In the Name of Allah
//La ilaha illallah Muhammadur Rasulullah
//Rabbir Hamhuma Kama Rabba Yani Sagheera
#include<bits/stdc++.h>
using namespace std;
#define Alhamdulillah ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define pll pair<ll,ll>
#define vp vector<pair<ll,ll>>
#define pb push_back
#define ff first
#define ss second
#define pi acos(-1.0)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define EPS 1e-9
ll ceilAB(ll a, ll b) { return (a + b - 1) / b; }
ll Pow(ll c, ll d) {return d == 0 ? 1 : c * pow(c, d - 1);}
ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return ((a * b) / gcd(a, b));}
const int mx = 1e6;
int a[mx];
void solve()
{
int i, j, k , n, m, x, y, z, c = 0, cnt = 0, mn = 1e9, l, r;
string s;
cin >> n >> m;
for (i = 1; i <= m; i++)
{
cin >> x >> y;
z = y - x + 1;
if (z < mn)
{
mn = z;
l = x;
r = y;
}
}
c = 0;
for (i = l; i <= n; i++)
{
a[i] = c;
c++;
if (c == mn)
{
c = 0;
}
}
c = mn - 1;
for (i = l - 1; i >= 1; i--)
{
a[i] = c;
c--;
if (c < 0)
{
c = mn - 1;
}
}
cout << mn << endl;
for (i = 1; i <= n; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
int main()
{
Alhamdulillah;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
}
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |
Number of triangles | AND path in a binary tree |
Factorial equations | Removal of vertices |
Happy segments | Cyclic shifts |
Zoos | Build a graph |
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |
Special sets | Smallest chosen word |
Going to office | Color the boxes |
Missing numbers | Maximum sum |
13 Reasons Why | Friend's Relationship |